package com.seatwork;

import javax.naming.InterruptedNamingException;
import javax.naming.InvalidNameException;

/**
 * @desecr
 * @Author Haibian
 * @Time 2018/9/28
 **/
public class  Employee {
    private int id;
    private String name;
    private int age;
    private double salary;
    private String identityCardNo;

    public Employee(){}

    public Employee(int id, String name, int age, double salary, String identityCardNo) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.salary = salary;
        this.identityCardNo = identityCardNo;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) throws NonExistsJobNumberException {
        if(id>=1001&&id<=1999){
            this.id = id;
        }else{
            throw new NonExistsJobNumberException("工号不存在");
        }

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if(name!=null&&!name.equals("")){
        this.name = name;
        }else{
            throw new NullPointerException("姓名不能为空");
        }

    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws IllegalAgeException {
        if(age>=18&&age<=35){
            this.age = age;
        }else{
            throw new IllegalAgeException("年龄必须是18岁到35岁之间");
        }

    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary)throws IllegalSalaryException {
        if(salary>=0){
            this.salary = salary;
        }else{
            throw new IllegalSalaryException("非法工资异常");
        }

    }

    public String getIdentityCardNo() {
        return identityCardNo;
    }

    public void setIdentityCardNo(String identityCardNo)throws IllegaldentityCardNoException{
        if(identityCardNo.length()==18){
            this.identityCardNo = identityCardNo;
        }else{
            throw new IllegaldentityCardNoException("身份证号异常");
        }

    }


    public void addSalary(double salary)throws IllegalSalaryException{
        if(salary<0){
            throw new IllegalSalaryException("非法工资异常");
        }else{
            double i =getSalary();
            setSalary(salary+=i);
        }
    }

    public void minusSalary(double salary)throws IllegalSalaryException {
        if (salary < 0) {
            throw new IllegalSalaryException("非法工资异常");
        } else {
            double i =getSalary()-salary;
            if(i<3000){
                throw new IllegalSalaryException("员工工资不能低于标准工资");
            }else{
                this.setSalary(i);
            }
        }
    }

    public void showSalary(){
        System.out.println("姓名："+getName()+"，工号："+getId()+"，年龄："+getAge()+"，身份证号码："+getIdentityCardNo()
        +"，工资："+getSalary());
    }
}
